package Classroom.A0510.PolyPra;

public class DownPra {
    public static void main(String[] args) {
        //  鸵鸟 是 鸟   鸽子  是 鸟   向上转型
        Bird bird = new Ostrich();
        bird = new Pigeon();
        //鸟是鸽子  不一定   向下转型   可能出现ClassCastException
//        Pigeon pigeon =(Pigeon) new Bird();
        Bird bird2 = new Pigeon();
        Pigeon pigeon = null;
        //为了避免出现向下转型异常   要先检查后转型
        //instanceof      对象  instanceof  类型
        if (bird2 instanceof Pigeon) {
            pigeon = (Pigeon) bird2;
        }
    }

}

//鸟
class Bird{

}

//鸵鸟
class Ostrich extends Bird{

}

//鸽子
class Pigeon extends Bird{
}
